home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_100
/
178_01
/
tvx_unix.c
< prev
Wrap
C/C++ Source or Header
|
1986-01-16
|
14KB
|
583 lines
/* -------------------------- tvx_unix.c ------------------------------ */
#include "tvx_defs.ic"
#include "tvx_glbl.ic"
#define TEMPEXT ".$$1" /* temporary file */
#define BACKEXT ".B" /* backup file */
#define SWITCH '-'
#define FILESEP '.'
/* define USETMP if you want intermediate workfiles built on
/tmp. Otherwise, they will be built on the same directory as
the original file. This latter method is often a bit faster,
especially when exiting if /tmp is on a different volume than
the destination file (which makes mv COPY the file rather than
just renameing. */
/* #define USETMP */ /* define if create temp files on /tmp */
#include <ctype.h>
#include <sys/ioctl.h>
#include <sys/types.h>
/* -------------- terminal I/O stuff --------------- */
static struct sgttyb sgb;
static struct tchars tch;
static struct ltchars ltc;
#define Ioctl ioctl
#define Read read
#define Write write
/* ------------- file mode stuff ---------------------- */
#include <sys/stat.h>
static struct stat info; /* structure to get info */
/* ------------- misc stuff ---------------------- */
extern int errno;
extern char **environ;
#ifdef TERMCAP /* routines needed for termcap */
/* ------------- termcap stuff ---------------------- */
char PC;
char *BC;
char *UP;
char TERM[40];
short ospeed;
static char Tcm[80]; /* special entry for cm */
static char empty[2];
static char Tbc[20];
static char Tup[20];
static int Tco, /* number of columns per line */
Tli; /* number of lines */
static char tcbuff[1024]; /* buffer to hold termcap entry */
/* ==========================>>> gettermcap <<<========================= */
gettermcap()
{
char *tp;
char *getenv();
char entry[80]; /* scratch buffer for entry */
empty[0] = 0;
ospeed = sgb.sg_ospeed; /* get the speed */
if ((tp = getenv("TERM")) == NULL)
{
goto FORCETTY;
}
strcpy(TERM,tp); /* copy to our TERM */
if (tgetent(tcbuff,TERM) < 1)
{
goto FORCETTY;
}
/* read required termcap entries, save in appropriate TVX arrays */
if (!gettcap("cm",Tcm))
{
goto FORCETTY;
}
if (!gettcap("ce",entry))
{
goto FORCETTY;
}
if (!capcpy(celin,entry,7)) /* copy entry to end of line */
{
goto FORCETTY;
}
gettcap("cd",entry); /* clear to end of display */
capcpy(cescr,entry,7);
gettcap("al",entry); /* insert a line (add line) */
capcpy(ciline,entry,7);
gettcap("dl",entry); /* delete a line */
capcpy(ckline,entry,7);
if (!gettcap("sr",entry)) /* reverse scroll */
{
strcpy(ctopb,ciline); /* add line works the same */
}
else
capcpy(ctopb,entry,7);
gettcap("ve",entry); /* stand cursor changer end */
capcpy(ccsrcm,entry,7);
gettcap("vs",entry); /* stand cursor changer begin */
capcpy(ccsrin,entry,7);
gettcap("se",entry); /* stand out end */
capcpy(cbolde,entry,7);
gettcap("so",entry); /* begin standout */
capcpy(cboldb,entry,7);
cerred[0] = 7; /* bell for sure */
gettcap("vb",entry); /* visual bell? */
if (*entry)
capcpy(cerred,entry,7);
if (!capcpy(&cversn[1],TERM,10)) /* copy name to version */
strcpy(cversn,"TERMCAP");
if ((Tco = tgetnum("co")) < 0) /* # of cols */
Tco = 79; /* assume 80 x 24 */
if ((Tli = tgetnum("li")) < 0) /* # of lines */
Tli = 24; /* assume 80 x 24 */
tvhardlines = tvlins = Tli; /* number of lines */
tvcols = Tco - 1; /* set col val (-1 avoids all the line wrap crap )*/
if (tvhardlines != 24 || tvhardlines != 25) /* strange terminal */
{
ddline = (tvlins / 2) + 1;
setdscrl(); /* calculate scroll */
}
gettcap("bc",entry); /* get backspace character */
if (!*entry)
{
Tbc[0] = 8; Tbc[1] = 0;
}
else
capcpy(Tbc,entry,19);
BC = Tbc;
gettcap("up",entry); /* get backspace character */
if (!*entry)
{
Tup[0] = 0;
}
else
capcpy(Tup,entry,19);
UP = Tup;
gettcap("pc",entry); /* get the pad character */
PC = *entry;
gettcap("is",entry); /* initialization string */
tcapcs(entry); /* send the intialization string */
gettcap("ti",entry); /* cm initialization string */
tcapcs(entry); /* send the intialization string */
return;
FORCETTY:
force_tty = TRUE;
remark("Unable to set up for video terminal, tty mode assumed.");
strcpy(cversn,"tty");
}
/* =============================>>> capcpy <<<============================= */
capcpy(to,from,len)
char *to, *from;
int len;
{ /* copy a capability, checking length */
if (strlen(from) > len)
{
*to = 0;
return (FALSE);
}
else
strcpy(to,from);
return (TRUE);
}
/* =============================>>> gettcap <<<============================= */
gettcap(cap,area)
char *cap, *area;
{
char **cpp, *cp;
cpp = &cp; /* I think */
cp = area;
*area = 0; /* assume null entry */
tgetstr(cap,cpp); /* get the capability */
return (*area); /* return 1st char */
}
/* =============================>>> tcapcs <<<============================= */
tcapcs(str)
char *str;
{
/* send a termcap generated control string to terminal */
register char *cp;
int ttwt();
if (!(echof && !bakflg && !ttymode))
return;
if (!*str) /* don't send null strings */
return;
cp = str;
tputs(cp,1,ttwt);
}
/* =============================>>> tcapxy <<<============================= */
tcapxy(x,y)
int x,y;
{
/* move cursor to x,y */
char *tgoto();
tcapcs(tgoto(Tcm,x-1,y-1)); /* send the string, adjusting x,y */
}
#endif /* termcap */
/* =============================>>> ttinit <<<============================= */
ttinit()
{
struct sgttyb nsgb;
struct tchars ntch;
struct ltchars nltc;
(void) Ioctl(0, TIOCGETP, &sgb);
(void) Ioctl(0, TIOCGETP, &nsgb);
(void) Ioctl(0, TIOCGETC, &tch);
(void) Ioctl(0, TIOCGETC, &ntch);
(void) Ioctl(0, TIOCGLTC, <c);
nsgb.sg_flags |= CBREAK;
nsgb.sg_flags &= ~(CRMOD|ECHO|LCASE|TANDEM);
ntch.t_intrc = -1; /* interrupt */
ntch.t_quitc = -1; /* quit */
/* the following two lines control flow control */
#ifndef FLOWCONTROL
ntch.t_startc = -1; /* start output */
ntch.t_stopc = -1; /* stop output */
#endif
ntch.t_eofc = -1; /* end-of-file */
ntch.t_brkc = -1; /* input delimiter (like nl) */
nltc.t_suspc = -1; /* stop process signal */
nltc.t_dsuspc = -1; /* delayed stop process signal */
nltc.t_rprntc = -1; /* reprint line */
nltc.t_flushc = -1; /* flush output (toggles) */
nltc.t_werasc = -1; /* word erase */
nltc.t_lnextc = -1; /* literal next character */
(void) Ioctl(0, TIOCSETP, &nsgb);
(void) Ioctl(0, TIOCSETC, &ntch);
(void) Ioctl(0, TIOCSLTC, &nltc);
#ifdef TERMCAP
gettermcap(); /* set up terminal characteristics */
#endif
info.st_mode = -1; /* no mode stuff yet */
}
/* =============================>>> ttrd_unix <<<============================= */
ttrd_unix()
{
char c;
Read(0, &c, 1);
return(c);
}
/* =============================>>> ttwtln <<<============================= */
ttwtln(cbuf,cnt)
char *cbuf;
int cnt;
{
if (echof && !bakflg && !ttymode)
Write(1, cbuf, cnt);
}
/* =============================>>> ttwt <<<============================= */
ttwt(c)
char c;
{
if (ttymode)
return;
Write(1, &c, 1);
}
/* =============================>>> ttclos <<<============================= */
ttclos()
{
#ifdef TERMCAP
char entry[80];
gettcap("te",entry); /* cm end up string */
tcapcs(entry); /* send it */
#endif
(void) Ioctl(0, TIOCSETP, &sgb);
(void) Ioctl(0, TIOCSETC, &tch);